package com.example.demo.netty.udp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.ReferenceCountUtil;

/**
 * Created by shangfei on 2018/7/10.
 */
public class ClientHandler extends SimpleChannelInboundHandler {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf buf = (ByteBuf) msg;

        byte[] data = new byte[buf.readableBytes()];
        buf.readBytes(data);
        String request = new String(data, "utf-8");
        System.out.println("服务端返回数据：" + request);
        buf.retain();
        ReferenceCountUtil.release(msg);
        //ctx.writeAndFlush(Unpooled.copiedBuffer(("服务端返回数据：" + request).getBytes()));

    }
}
